package com.stox.core.util;

import com.stox.core.model.BarValueType;
import com.stox.core.model.IBar;

public class BarUtil {

	public static double getValue(IBar bar, BarValueType barValueType){
		if(bar != null && barValueType != null){
			switch(barValueType){
			case CLOSE : return bar.getClose();
			case HIGH : return bar.getHigh();
			case LOW : return bar.getLow();
			case MID : return (bar.getHigh()+bar.getLow())/2;
			case OPEN : return bar.getOpen();
			case VOLUME : return bar.getVolume();
			case SPREAD : return bar.getHigh() - bar.getLow();
			}
		}
		return 0;
	}
	
	public static void copy(IBar from, IBar to){
		to.setScripCode(from.getScripCode());
		to.setDate(from.getDate());
		to.setOpen(from.getOpen());
		to.setHigh(from.getHigh());
		to.setLow(from.getLow());
		to.setClose(from.getClose());
		to.setVolume(from.getVolume());
	}
	
}
